package com.yanqu.road.server.cmd.activity.relation.cross;

import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.pb.cookboyactivity.CookBoyActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.RelationActivityModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_CROSS_COOK_BOY_GET_SPECIAL_REWARD_NOTIFY, desc = "跨服领取奖励通知")
public class CrossRelationGetSpecialNotifyCmd extends AbstractCommand {
	private int activityId;
	private int conditionId;
	private String params;
	private String crossParams;
	private ActivityRewardResult rewardResult;
	private boolean oneKey;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CookBoyActivityProto.CrossActivityGetSpecialRewardRespMsg reqMsg = CookBoyActivityProto.CrossActivityGetSpecialRewardRespMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		conditionId = reqMsg.getConditionId();
		params = reqMsg.getParams();
		crossParams = reqMsg.getCrossParams();
		oneKey = reqMsg.getOneKey();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(oneKey){
			rewardResult = player.getModule(RelationActivityModule.class).getCrossSpecialRewardOneKey(activityId, conditionId, params, crossParams);
		}else {
			rewardResult = player.getModule(RelationActivityModule.class).getCrossSpecialReward(activityId, conditionId, params, crossParams);
		}
	}

	@Override
	public void sendData(GamePlayer player) {
		CookBoyActivityProto.CookBoyActivityGetRewardRespMsg.Builder respMsg = CookBoyActivityProto.CookBoyActivityGetRewardRespMsg.newBuilder();
		respMsg.setRet(rewardResult.getRet());
		if(0 == respMsg.getRet()){
			respMsg.setReward(rewardResult.getReward());
		}
		if(oneKey){
			player.sendPacket(Protocol.U_COOK_BOY_ACTIVITY_GET_REWARD_ONE_KEY, respMsg);
		}else {
			player.sendPacket(Protocol.U_COOK_BOY_ACTIVITY_GET_REWARD, respMsg);
		}
	}

}
